﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace BotvaBot.Configuration
{
    public abstract class CustomConfigElementBase : ConfigurationElement
    {
        protected Dictionary<string, object> InnerValues = null;

        public CustomConfigElementBase()
            : base()
        {
            InnerValues = new Dictionary<string,object>();
        }

        [ConfigurationProperty("Name")]
        public string Name
        {
            get { return (String)base["Name"]; }
        }

        public object ElementKey
        {
            get { return Name; }
        }


        public void ClearCustomValue(string propertyName)
        {
            if (InnerValues.ContainsKey(propertyName))
                InnerValues.Remove(propertyName);
        }

        protected T Get<T>(string propertyName)
        {
            if (InnerValues.ContainsKey(propertyName))
                return (T)InnerValues[propertyName];
            else
                return (T)base[propertyName];
        }

        public object this[string propertyName]
        {
            get
            {
                if (InnerValues.ContainsKey(propertyName))
                    return InnerValues[propertyName];
                else
                    return base[propertyName];
            }
            set
            {
                if (InnerValues.ContainsKey(propertyName))
                    InnerValues[propertyName] = value;
                else
                    InnerValues.Add(propertyName, value);
            }
        }
    }
}
